<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
    <el-form-item label="评估指标I编号" prop="evaluateindex1id">
      <el-input v-model="ruleForm.evaluateindex1id"></el-input>
    </el-form-item>
    <el-form-item label="评估指标I名称" prop="evaluatename">
      <el-input v-model="ruleForm.evaluateindex1name"></el-input>
    </el-form-item>
    <el-form-item label="评估号" prop="evaluateid">
      <el-input v-model="ruleForm.evaluateid"></el-input>
    </el-form-item>
    <el-form-item label="评估指标I内容" prop="evaluateindex1content">
      <el-input v-model="ruleForm.evaluateindex1content"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">立即添加</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        // id:'',
        evaluateindex1id: '',
        evaluateindex1name: '',
        evaluateid:'',
        evaluateindex1content:''
      },
      rules: {
        // id: [
        //   { required: true, message: '请填写编号 注意与已存在的编号不要重复', trigger: 'blur' }
        // ],
        evaluateindex1id: [
          { required: true, message: '请填写评估指标I编号', trigger: 'blur' }
        ],
        evaluateindex1name: [
          { required: true, message: '请填写评估指标I名称', trigger: 'blur' }
        ],
        evaluateid: [
          { required: true, message: '请填写评估号', trigger: 'blur' }
        ],
        evaluateindex1content: [
          { required: true, message: '请填写评估指标I内容', trigger: 'blur' }
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios.post("http://localhost:8081/evaluateindex1/save",this.ruleForm).then(function (res){
            if (res.data.msg==="添加成功"){
              _this.$message({
                message: '添加成功！',
                type: 'success'
                //添加成功后页面跳转
              });
              _this.$router.push('/EvaluateIndex123')
            }
            else{
              _this.$message({
                message: '评估号不存在或者评估指标I编号重复！请重新输入',
                type: 'fail'
              });
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const a=localStorage.getItem("access-admin")
    if (!a){
      this.$alert('未登录','提示',{
        confirmButtonText:'确定'
      }).then((res)=>{
        this.$router.replace({path:'/login'})
      })
    }
  }
}
</script>